home *** CD-ROM | disk | FTP | other *** search
/ PC World Interactive 7 / PC World Interactive 7.iso / bb2000 / files / BlueGame.dxr / 00176_carScript.ls < prev    next >
Encoding:
Text File  |  1998-02-20  |  5.0 KB  |  184 lines

  1. property carYpos, carXpos, CAR, carIsDrivingHori, carIsDrivingVert, myDirection, myCounter, myRatio, finalYpos, finalXpos, freezedCar
  2. global myGridArray, gGamesMasterObj, noWayBubList, BLOCKWIDTH, BLOCKHEIGHT
  3.  
  4. on new me
  5.   return me
  6. end
  7.  
  8. on init me, xPos, yPos, spritenum, ratioNum
  9.   set carXpos to xPos
  10.   set carYpos to yPos
  11.   set freezedCar to 0
  12.   set finalXpos to xPos
  13.   set finalYpos to yPos
  14.   set CAR to spritenum
  15.   set carIsDrivingHori to 0
  16.   set carIsDrivingVert to 0
  17.   set myDirection to 0
  18.   set myCounter to 0
  19.   set myRatio to ratioNum
  20.   appear(me, "carN.PCT")
  21. end
  22.  
  23. on appear me, membername
  24.   puppetSprite(the CAR of me, 1)
  25.   set the foreColor of sprite the CAR of me to 255
  26.   set the ink of sprite the CAR of me to 8
  27.   set the locH of sprite the CAR of me to ((the carXpos of me - 1) * BLOCKWIDTH) + (BLOCKWIDTH / 2)
  28.   set the locV of sprite the CAR of me to ((the carYpos of me - 1) * BLOCKHEIGHT) + (BLOCKHEIGHT / 2)
  29.   set the member of sprite the CAR of me to member membername
  30.   append(the actorList, me)
  31. end
  32.  
  33. on stepFrame me
  34.   mainRoutine(me)
  35. end
  36.  
  37. on mainRoutine me
  38.   if carIsDrivingHori then
  39.     set myCounter to myCounter + 1
  40.     if myCounter > (BLOCKWIDTH / myRatio) then
  41.       set finalXpos to carXpos
  42.       set carIsDrivingHori to 0
  43.     else
  44.       set the locH of sprite CAR to the locH of sprite CAR + (myDirection * myRatio)
  45.     end if
  46.   else
  47.     if carIsDrivingVert then
  48.       set myCounter to myCounter + 1
  49.       if myCounter > (BLOCKHEIGHT / myRatio) then
  50.         set finalYpos to carYpos
  51.         set carIsDrivingVert to 0
  52.       else
  53.         set the locV of sprite CAR to the locV of sprite CAR + (myDirection * myRatio)
  54.       end if
  55.     else
  56.       if not freezedCar then
  57.         case the keyPressed of gGamesMasterObj of
  58.           126:
  59.             checkCar(me, 1)
  60.           124:
  61.             checkCar(me, 2)
  62.           125:
  63.             checkCar(me, 3)
  64.           123:
  65.             checkCar(me, 4)
  66.         end case
  67.       end if
  68.     end if
  69.   end if
  70. end
  71.  
  72. on checkCar me, indexNum
  73.   if not carIsDrivingVert and not carIsDrivingHori then
  74.     set myOptions to getIndex(me, myGridArray, carYpos, carXpos)
  75.     if getAt(myOptions, indexNum) = 1 then
  76.       killBubbles(gGamesMasterObj, noWayBubList)
  77.       case indexNum of
  78.         1:
  79.           set carYpos to carYpos - 1
  80.           if nextSpaceFree(me) then
  81.             set the member of sprite CAR to member "carN.PCT"
  82.             moveVertical(me, -1)
  83.           else
  84.             set carYpos to carYpos + 1
  85.           end if
  86.         2:
  87.           set carXpos to carXpos + 1
  88.           if nextSpaceFree(me) then
  89.             set the member of sprite CAR to member "carE.PCT"
  90.             moveHorizontal(me, 1)
  91.           else
  92.             set carXpos to carXpos - 1
  93.           end if
  94.         3:
  95.           set carYpos to carYpos + 1
  96.           if nextSpaceFree(me) then
  97.             set the member of sprite CAR to member "carS.PCT"
  98.             moveVertical(me, 1)
  99.           else
  100.             set carYpos to carYpos - 1
  101.           end if
  102.         4:
  103.           set carXpos to carXpos - 1
  104.           if nextSpaceFree(me) then
  105.             set the member of sprite CAR to member "carW.PCT"
  106.             moveHorizontal(me, -1)
  107.           else
  108.             set carXpos to carXpos + 1
  109.           end if
  110.       end case
  111.     else
  112.       if noWayBubList = [] then
  113.         set horPos to the locH of sprite CAR
  114.         set verPos to the locV of sprite CAR
  115.         if horPos < 280 then
  116.           set xPos to horPos + 15
  117.           set hCode to 4
  118.         else
  119.           set xPos to horPos - 15
  120.           set hCode to 2
  121.         end if
  122.         if verPos < 180 then
  123.           set yPos to verPos + 15
  124.           set vCode to 1
  125.         else
  126.           set yPos to verPos - 15
  127.           set vCode to 3
  128.         end if
  129.         set bubbleObj to new(script "bubbleScript")
  130.         set myMember to getAt(["band", "move", "miss"], random(3))
  131.         appear(bubbleObj, xPos, yPos, myMember & vCode & hCode & ".PCT", noWayBubList)
  132.       end if
  133.     end if
  134.   end if
  135. end
  136.  
  137. on changeCar me, myString
  138.   set myName to the name of the member of sprite the CAR of me
  139.   set myDir to chars(myName, 4, 4)
  140.   set the member of sprite the CAR of me to member string(myString & myDir & ".PCT")
  141. end
  142.  
  143. on moveVertical me, direction
  144.   set the myCounter of me to 0
  145.   set the myDirection of me to direction
  146.   set the carIsDrivingVert of me to 1
  147. end
  148.  
  149. on moveHorizontal me, direction
  150.   set the myCounter of me to 0
  151.   set the myDirection of me to direction
  152.   set the carIsDrivingHori of me to 1
  153. end
  154.  
  155. on getIndex me, list, iPos, jPos
  156.   return getAt(getAt(list, iPos), jPos)
  157. end
  158.  
  159. on setIndex me, list, iPos, jPos, myValue
  160.   setAt(getAt(list, iPos), jPos, myValue)
  161. end
  162.  
  163. on destroy me
  164.   set the memberNum of sprite the CAR of me to 0
  165.   set pos to getPos(the actorList, me)
  166.   if pos > 0 then
  167.     deleteAt(the actorList, pos)
  168.   end if
  169.   return me
  170. end
  171.  
  172. on nextSpaceFree me
  173.   repeat with i = 2 to count(the actorList)
  174.     set myObject to getAt(the actorList, i)
  175.     if the CAR of myObject <> CAR then
  176.       if (the carXpos of myObject = carXpos) and (the carYpos of myObject = carYpos) then
  177.         return 0
  178.         exit repeat
  179.       end if
  180.     end if
  181.   end repeat
  182.   return 1
  183. end
  184.